# -*- coding: utf-8 -*-
import wmi
class applys():
    def __init__(self, nic_id=1):
        '''
        初始化一个网卡实例
        :param nic_id:输入一个网卡ID(1是第一个，所以实际值需要： ID + 1 )
        '''
        self.nic_id = int(nic_id) - 1
        self.wmiService = wmi.WMI()
        self.colNicConfigs = self.wmiService.Win32_NetworkAdapterConfiguration(IPEnabled=True)
        self.nic = self.colNicConfigs[self.nic_id]
    def set_ip(self, IP, MASK):
        '''
        :param IP: 设置一个静态的IPV4地址
        :param MASK: 设置子网掩码参数
        '''
        try:
            print(IP, MASK)
            self.nic.EnableStatic(IP, MASK)
            return 0
        except:
            return 404
up = applys(nic_id=1)
up.set_ip(IP='10.8.0.12', MASK='255.255.255.0')